<!DOCTYPE html>


<html lang="zh-CN">
  

    <head>
      <meta charset="utf-8" />
       
      <meta name="keywords" content="hi~" />
       
      <meta name="description" content="梦见新大陆" />
      
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title> 默</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css"
      />
      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="默" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      
<section class="cover">
    
  <div class="cover-frame">
    <div class="bg-box">
      <img src="/images/cover1.jpg" alt="image frame" />
    </div>
    <div class="cover-inner text-center text-white">
      <h1><a href="/">默</a></h1>
      <div id="subtitle-box">
        
        <span id="subtitle"></span>
        
      </div>
      <div>
        
      </div>
    </div>
  </div>
  <div class="cover-learn-more">
    <a href="javascript:void(0)" class="anchor"><i class="ri-arrow-down-line"></i></a>
  </div>
</section>



<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js"></script>


<!-- Subtitle -->

  <script>
    try {
      var typed = new Typed("#subtitle", {
        strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
        startDelay: 0,
        typeSpeed: 200,
        loop: true,
        backSpeed: 100,
        showCursor: true
      });
    } catch (err) {
      console.log(err)
    }
  </script>
  
<div id="main">
  <section class="outer">
  
  
  

<div class="notice" style="margin-top:50px">
    <i class="ri-heart-fill"></i>
    <div class="notice-content" id="broad"></div>
</div>
<script type="text/javascript">
    fetch('https://v1.hitokoto.cn')
        .then(response => response.json())
        .then(data => {
            document.getElementById("broad").innerHTML = data.hitokoto;
        })
        .catch(console.error)
</script>

<style>
    .notice {
        padding: 20px;
        border: 1px dashed #e6e6e6;
        color: #969696;
        position: relative;
        display: inline-block;
        width: 100%;
        background: #fbfbfb50;
        border-radius: 10px;
    }

    .notice i {
        float: left;
        color: #999;
        font-size: 16px;
        padding-right: 10px;
        vertical-align: middle;
        margin-top: -2px;
    }

    .notice-content {
        display: initial;
        vertical-align: middle;
    }
</style>
  
  <article class="articles">
    
    
    
    
    <article
  id="post-storybook-js"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/12/24/storybook-js/"
    >Storybook从零到一搭建组件库(上篇)</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/12/24/storybook-js/" class="article-date">
  <time datetime="2021-12-24T09:52:09.303Z" itemprop="datePublished">2021-12-24</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>Storybook 是一个绝妙的 组件驱动开发环境。它通过隔离组件使开发更快更容易，它可以一次只处理一个组件。在 web 应用程序中构建小的原子组件和复杂的页面，使用 Storybook 可以让你专注于组件开发，无需去关注 API 文档的编写。</p>
<blockquote>
<p>Storybook 可以做什么？</p>
</blockquote>
<p>工作中开发的 UI 组件或页面可以用 Storybook 帮助你记录并生成 API 文档，增强代码重用性，大大的提高工作效率，并自动可视化地测试组件以防止 bug。<br>同时不受限于框架，它同时支持 Vue、React、Angular。所以工作的同时，不妨用它来沉淀一个自己的组件库，面试的时候也是一个谈资。<br><img src="/2021/12/24/storybook-js/image.png" alt="image"></p>
<h2 id="依赖技术栈"><a href="#依赖技术栈" class="headerlink" title="依赖技术栈"></a>依赖技术栈</h2><p>首先，先来了解一下搭建一个简单的 UI 组件库需要使用哪些技术栈：</p>
<ol>
<li>Node 环境：v14.16.1</li>
<li>React@17：用于构建用户界面的 JavaScript 库</li>
<li>TypeScript@^4.5.4：Javascript 类型的超集，有强大的编码提示功能</li>
<li>Ant-design@^4.17.4：最流行的 React 项目 UI 组件库，要搭建的基础组件库是基于 Ant Design 做的二次封装</li>
<li>Create React App：React 脚手架快捷搭建项目架构</li>
<li>Storybook（@storybook/react@^6.4.9）：辅助 UI 控件开发的工具，通过 story 创建独立的控件，让每个控件开发都有一个独立的开发调试环境；</li>
<li>Prettier&amp;Eslint&amp;husky：统一规范代码风格交给 Prettier、Eslint 校验语法错误，husky 预防将带有语法等错误提交到远程仓库造成污染</li>
<li>Webpack@^5.0.0：静态模块打包工具</li>
</ol>
<h2 id="项目准备"><a href="#项目准备" class="headerlink" title="项目准备"></a>项目准备</h2> 
      <a class="article-more-link" href="/2021/12/24/storybook-js/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Storybook/" rel="tag">Storybook</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%A1%86%E6%9E%B6%E5%AD%A6%E4%B9%A0/" rel="tag">框架学习</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-2021-summary"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/12/24/2021-summary/"
    >2021，沪漂五年重返校园的一年</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/12/24/2021-summary/" class="article-date">
  <time datetime="2021-12-24T09:52:09.279Z" itemprop="datePublished">2021-12-24</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p><img src="/2021/12/24/2021-summary/banner.jpg" alt="img"><br>2021 年，依然是为生活忙碌的一年，考研、考证、换工作……</p>
<p>回想起去年此时正在紧张的备战考研，或许是年龄大了心态不如从前了，考试前夕特别焦虑一度失眠。不过过程都不重要了，因为结果还不错，现在已经入学半学期啦～</p>
<h2 id="工作"><a href="#工作" class="headerlink" title="工作"></a>工作</h2><h3 id="我换工作了-💻"><a href="#我换工作了-💻" class="headerlink" title="我换工作了 💻"></a>我换工作了 💻</h3><p>就在今年 10 月底我离开了工作两年多的公司，不是裸辞，这个年纪已经没有了裸辞的勇气，原因一言难尽，其实年中就打算走的，但面试了一周左右没有理想的 offer 加之领导的挽留，我放弃了面试，不过 10 月底做完项目后拿到了满意的 offer 还是走了。</p>
<p>回想在那里的两年，平台虽然不大，但是很开心认识了一群可爱的小伙伴和我的的老大(庄哥)，他的技术很牛，跟他学到了很多东西，他的技术和为人处事都值得我学习，他是 Coach 型的老大，是我的理想 leader。不过他在我之前离职了，说实话知道他要走的时候我很难过，不知道你们有没有那种很慌又孤军奋战的感觉，感觉工作都提不起兴趣，不过慢慢还是要习惯要自己强大起来。</p> 
      <a class="article-more-link" href="/2021/12/24/2021-summary/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%B9%B4%E7%BB%88%E6%80%BB%E7%BB%93/" rel="tag">年终总结</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-Formily-demo"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/12/01/Formily-demo/"
    >Formily入门实践</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/12/01/Formily-demo/" class="article-date">
  <time datetime="2021-12-01T15:14:30.000Z" itemprop="datePublished">2021-12-01</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>Formily 是阿里开源的动态化表单的解决方案，优雅的解决了多种复杂场景的表单的数据、状态管理及夸表单通信问题，同时规避了全量渲染的弊端，性能优越。刚好满足我近期工作中的业务需求，啃了将近一周的文档，对 Family 有了初步的了解，后续使用起来再出翻坑指南。</p>
<h2 id="初步了解"><a href="#初步了解" class="headerlink" title="初步了解"></a>初步了解</h2><p>​Formily 基于 MVVM 的设计原则，常用的基础核心库有<code>@formily/core</code>、<code>@formily/react</code>、<code>@formily/vue</code>、<code>@formily/antd</code>，支持 react 和 vue，同时支持 Markup Schema、 JSX 以及现在业界最流行的 JSON Schema 的写法。</p>
<p>Formily 分为了<strong>内核层</strong>，<strong>UI 桥接层</strong>，<strong>扩展组件层</strong>，和<strong>配置应用层</strong>，如下图。<br><strong>内核层</strong>是 UI 无关的，它保证了用户管理的逻辑和状态是不耦合任何一个框架。<br>JSON Schema 独立存在，给 UI 桥接层消费，保证了协议驱动在不同 UI 框架下的绝对一致性，不需要重复实现协议解析逻辑。<br><strong>扩展组件层</strong>，提供一系列表单场景化组件，保证用户开箱即用。无需花大量时间做二次开发。<br><img src="/2021/12/01/Formily-demo/image.png" alt="Formily的分层架构图"></p>
<blockquote>
<p>核心优势</p>
<ul>
<li>高性能</li>
<li>开箱即用</li>
<li>联动逻辑实现高效</li>
<li>跨端能力，逻辑可跨框架，跨终端复用</li>
<li>动态渲染能力</li>
</ul>
</blockquote>
<p>核心劣势：学习成本较高，需引多个包，包体积较大。<br>​</p>
<p>确实 Formily 的学习成本还是相对较高的，几大核心库一堆的文档和 API 会让你眼花缭乱，但是既然要学就要耐下心来，思路理清之后就轻车熟路了。<br>​</p>
<p>核心库介绍：<br><code>@formily/core</code>：<strong>ViewModel 层</strong>，负责管理表单的状态，表单校验，联动等等。<br><code>@formily/react</code>：** Model 层<strong>，作为 UI 库来接入内核数据，用来实现最终的表单交互效果，对于不同框架的用户，使用有不同的桥接库，这里使用<code>react</code>为例，使用 vue 安装<code>@formily/vue</code>。<br><code>@formily/antd</code>：</strong>View 层**，在<code>Ant Design</code>基础之上封装的开箱即用的组件库。</p>
<h2 id="使用准备"><a href="#使用准备" class="headerlink" title="使用准备"></a>使用准备</h2><p>安装依赖，这里以<code>React+Antd </code>为例</p>
<p>使用 yarn<br><code>yarn add @formily/core</code><br><code>yarn add @formily/react</code><br><code>yarn add antd moment @formily/antd</code><br>​</p>
<p>or 使用 npm<br><code>npm install --save @formily/core</code><br><code>npm install --save @formily/react</code><br><code>npm install --save antd moment @formily/antd</code><br>​</p>
<p>导入依赖：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">&#x27;react&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; createForm &#125; <span class="keyword">from</span> <span class="string">&#x27;@formily/core&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; FormProvider, Field &#125; <span class="keyword">from</span> <span class="string">&#x27;@formily/react&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; FormItem, Input &#125; <span class="keyword">from</span> <span class="string">&#x27;@formily/antd&#x27;</span></span><br></pre></td></tr></table></figure>

<p>​</p>
<h2 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h2><p>以<code>JSON Schema</code>写法为例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">&#x27;react&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; createForm &#125; <span class="keyword">from</span> <span class="string">&#x27;@formily/core&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; createSchemaField, FormConsumer, FormProvider &#125; <span class="keyword">from</span> <span class="string">&#x27;@formily/react&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; FormItem, Input, Password, Submit, FormLayout, FormButtonGroup &#125; <span class="keyword">from</span> <span class="string">&#x27;@formily/antd&#x27;</span></span><br><span class="line"><span class="keyword">import</span> * <span class="keyword">as</span> ICONS <span class="keyword">from</span> <span class="string">&#x27;@ant-design/icons&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//用来创建表单核心领域模型，它是作为MVVM设计模式的标准 ViewModel</span></span><br><span class="line"><span class="keyword">const</span> form = createForm()</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建一个 SchemaField 组件用于解析JSON-Schema动态渲染表单的组件</span></span><br><span class="line"><span class="keyword">const</span> SchemaField = createSchemaField(&#123;</span><br><span class="line">  <span class="comment">// 组件列表</span></span><br><span class="line">  <span class="attr">components</span>: &#123;</span><br><span class="line">    FormLayout,</span><br><span class="line">    FormItem,</span><br><span class="line">    Input,</span><br><span class="line">    Password</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// 全局作用域，用于实现协议表达式变量注入</span></span><br><span class="line">  <span class="attr">scope</span>: &#123;</span><br><span class="line">    <span class="function"><span class="title">icon</span>(<span class="params">name: string</span>)</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> React.createElement(ICONS[name])</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">/**初始化一份json schema</span></span><br><span class="line"><span class="comment"> * 解析 json-schema 的能力；将 json-schema 转换成 Field Model 的能力；编译 json-schema 表达式的能力</span></span><br><span class="line"><span class="comment"> **/</span></span><br><span class="line"><span class="keyword">const</span> schema = &#123;</span><br><span class="line">  <span class="comment">// schema type</span></span><br><span class="line">  <span class="attr">type</span>: <span class="string">&#x27;object&#x27;</span>,</span><br><span class="line">  <span class="attr">properties</span>: &#123;</span><br><span class="line">    <span class="attr">layout</span>: &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;void&#x27;</span>,</span><br><span class="line">      <span class="string">&#x27;x-component&#x27;</span>: <span class="string">&#x27;FormLayout&#x27;</span>,</span><br><span class="line">      <span class="string">&#x27;x-component-props&#x27;</span>: &#123;</span><br><span class="line">        <span class="attr">labelCol</span>: <span class="number">2</span>,</span><br><span class="line">        <span class="attr">wrapperCol</span>: <span class="number">6</span>,</span><br><span class="line">        <span class="attr">labelAlign</span>: <span class="string">&#x27;right&#x27;</span></span><br><span class="line">        <span class="comment">// layout: &#x27;vertical&#x27;,</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="comment">// 属性描述</span></span><br><span class="line">      <span class="attr">properties</span>: &#123;</span><br><span class="line">        <span class="attr">username</span>: &#123;</span><br><span class="line">          <span class="comment">// schema type</span></span><br><span class="line">          <span class="attr">type</span>: <span class="string">&#x27;string&#x27;</span>,</span><br><span class="line">          <span class="comment">// 标题</span></span><br><span class="line">          <span class="attr">title</span>: <span class="string">&#x27;用户名&#x27;</span>,</span><br><span class="line">          <span class="comment">// 必填</span></span><br><span class="line">          <span class="attr">required</span>: <span class="literal">true</span>,</span><br><span class="line">          <span class="comment">// 字段 UI 包装器组件</span></span><br><span class="line">          <span class="string">&#x27;x-decorator&#x27;</span>: <span class="string">&#x27;FormItem&#x27;</span>,</span><br><span class="line">          <span class="comment">// 字段 UI 组件</span></span><br><span class="line">          <span class="string">&#x27;x-component&#x27;</span>: <span class="string">&#x27;Input&#x27;</span>,</span><br><span class="line">          <span class="comment">// 字段 UI 组件属性</span></span><br><span class="line">          <span class="string">&#x27;x-component-props&#x27;</span>: &#123;</span><br><span class="line">            <span class="attr">prefix</span>: <span class="string">&quot;&#123;&#123;icon(&#x27;UserOutlined&#x27;)&#125;&#125;&quot;</span></span><br><span class="line">          &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="attr">password</span>: &#123;</span><br><span class="line">          <span class="attr">type</span>: <span class="string">&#x27;string&#x27;</span>,</span><br><span class="line">          <span class="attr">title</span>: <span class="string">&#x27;密码&#x27;</span>,</span><br><span class="line">          <span class="attr">required</span>: <span class="literal">true</span>,</span><br><span class="line">          <span class="string">&#x27;x-decorator&#x27;</span>: <span class="string">&#x27;FormItem&#x27;</span>,</span><br><span class="line">          <span class="string">&#x27;x-decorator-props&#x27;</span>: &#123;</span><br><span class="line">            <span class="attr">addonAfter</span>: <span class="string">&#x27;强度高&#x27;</span></span><br><span class="line">          &#125;,</span><br><span class="line">          <span class="string">&#x27;x-component&#x27;</span>: <span class="string">&#x27;Password&#x27;</span>,</span><br><span class="line">          <span class="string">&#x27;x-component-props&#x27;</span>: &#123;</span><br><span class="line">            <span class="attr">prefix</span>: <span class="string">&quot;&#123;&#123;icon(&#x27;LockOutlined&#x27;)&#125;&#125;&quot;</span></span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> () =&gt; &#123;</span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    <span class="xml"><span class="tag">&lt;<span class="name">FormProvider</span> <span class="attr">form</span>=<span class="string">&#123;form&#125;</span>&gt;</span></span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;<span class="name">FormLayout</span> <span class="attr">layout</span>=<span class="string">&quot;vertical&quot;</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">SchemaField</span> <span class="attr">schema</span>=<span class="string">&#123;schema&#125;</span> /&gt;</span></span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;/<span class="name">FormLayout</span>&gt;</span></span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;<span class="name">FormButtonGroup</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">Submit</span> <span class="attr">onSubmit</span>=<span class="string">&#123;console.log&#125;</span>&gt;</span>提交<span class="tag">&lt;/<span class="name">Submit</span>&gt;</span></span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;/<span class="name">FormButtonGroup</span>&gt;</span></span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;<span class="name">FormConsumer</span>&gt;</span></span></span><br><span class="line"><span class="xml">        &#123;() =&gt; (</span></span><br><span class="line"><span class="xml">          <span class="tag">&lt;<span class="name">div</span></span></span></span><br><span class="line"><span class="tag"><span class="xml">            <span class="attr">style</span>=<span class="string">&#123;&#123;</span></span></span></span><br><span class="line"><span class="tag"><span class="xml">              <span class="attr">width:</span> <span class="attr">340</span>,</span></span></span><br><span class="line"><span class="tag"><span class="xml">              <span class="attr">marginTop:</span> <span class="attr">20</span>,</span></span></span><br><span class="line"><span class="tag"><span class="xml">              <span class="attr">padding:</span> <span class="attr">5</span>,</span></span></span><br><span class="line"><span class="tag"><span class="xml">              <span class="attr">border:</span> &#x27;<span class="attr">1px</span> <span class="attr">dashed</span> #<span class="attr">666</span>&#x27;</span></span></span><br><span class="line"><span class="tag"><span class="xml">            &#125;&#125;</span></span></span><br><span class="line"><span class="tag"><span class="xml">          &gt;</span></span></span><br><span class="line"><span class="xml">            实时响应-用户名：&#123;form.values.username&#125;</span></span><br><span class="line"><span class="xml">          <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">        )&#125;</span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;/<span class="name">FormConsumer</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;/<span class="name">FormProvider</span>&gt;</span></span></span><br><span class="line">  )</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="/2021/12/01/Formily-demo/img2.png" alt="image"></p>
<ul>
<li><code>FormProvider</code>组件是作为视图层桥接表单模型的入口，它只有一个参数，就是接收 <code>createForm</code>创建出来的 <code>Form </code>实例，并将 <code>Form </code>实例以上下文形式传递到子组件中。</li>
<li><code>FormLayout</code>组件是用来批量控制<code>FormItem</code>样式的组件，这里我们指定布局为水平布局，也就是标签在左，组件在右。</li>
<li><code>FormConsumer</code>组件是作为响应式模型的响应器而存在，它核心是一个<code>render props</code>模式，在作为 <code>children </code>的回调函数中，会自动收集所有依赖，如果依赖发生变化，则会重新渲染，借助 <code>FormConsumer </code>我们可以很方便的实现各种计算汇总的需求。</li>
<li><code>FormButtonGroup</code>组件作为表单按钮组容器而存在，主要负责按钮的布局。</li>
<li><code>Submit</code>组件作为表单提交的动作触发器而存在，其实我们也可以直接使用 <code>form.submit </code>方法进行提交，但是使用 <code>Submit </code>的好处是不需要每次都在 <code>Button </code>组件上写 <code>onClick </code>事件处理器，同时它还处理了 <code>Form </code>的 <code>loading </code>状态，如果 <code>onSubmit </code>方法返回一个 <code>Promise</code>，且 <code>Promise </code>正在 <code>pending </code>状态，那么按钮会自动进入 <code>loading </code>状态。</li>
</ul>
<blockquote>
<p><code>注意：使用前还需要了解，Formily 已经完全放弃对 IE 的兼容，如需兼容 IE，慎用！！！</code></p>
</blockquote>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a target="_blank" rel="noopener" href="https://formilyjs.org/">Formily 官方文档</a><br>​</p>
<p>​</p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.6.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.6.0/dist/mindmap.min.css"> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Formily/" rel="tag">Formily</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-webpack-happyPack"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/11/26/webpack-happyPack/"
    >webpack之HappyPack</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/11/26/webpack-happyPack/" class="article-date">
  <time datetime="2021-11-26T15:14:30.000Z" itemprop="datePublished">2021-11-26</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <blockquote>
<p>HappyPack makes initial webpack builds faster by transforming files in parallel.<br>HappyPack 通过并行转换文件，使初始 webpack 构建速度更快。</p>
</blockquote>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>webpack中万物皆模块，但是webpack默认只能处理js模块，那么js以外的模块怎么处理呢，所以就有了loader机制，比如：vue-loader、css-loader、file-loader等等。loader是一个导出为function的node模块。可以将匹配到的文件进行一次转换，同时loader可以链式传递。如果项目比较复杂，构建时就会有大量文件需要解析和处理，构建是文件读写和计算密集型的操作，大型项目中webpack构建慢的问题尤为显著，然而运行在nodejs环境的webpack是单线程的，如果能让webpack同一时间能做多项任务，发挥多核 CPU 电脑的威力，就能大大的提升构建速度。这时候HappyPack就闪亮登场了，它把任务分解给多个子进程去并发的执行，子进程处理完后再把结果发送给主进程，相比之前可以有效的提升构建速度。<br>更多loaders内容参考<a target="_blank" rel="noopener" href="https://webpack.docschina.org/loaders/">https://webpack.docschina.org/loaders/</a><br>​</p>
<blockquote>
<p>线程和进程都可用于实现并发，一个进程由一个或多个线程组成，线程是一个进程中代码的不同执行路线。</p>
</blockquote>
<h2 id="使用HappyPack"><a href="#使用HappyPack" class="headerlink" title="使用HappyPack"></a>使用HappyPack</h2><p>HappyPack提供了一个plugin和一个load完成它的工作，所以你必须同时使用两者来启用它。<br>使用npm：<br><code>npm install --save-dev happypack</code><br>使用yarn：<br><code>yarn add happypack --dev</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// @file: webpack.config.js</span></span><br><span class="line"><span class="keyword">var</span> HappyPack = <span class="built_in">require</span>(<span class="string">&#x27;happypack&#x27;</span>);</span><br><span class="line"><span class="comment">// 构造出共享进程池，进程池中包含5个子进程</span></span><br><span class="line"><span class="keyword">var</span> happyThreadPool = HappyPack.ThreadPool(&#123; <span class="attr">size</span>: <span class="number">5</span> &#125;);</span><br><span class="line"> &lt;!--more--&gt;</span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="attr">module</span>: &#123;</span><br><span class="line">    <span class="attr">rules</span>: [</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="attr">test</span>: <span class="regexp">/\.js$/</span>,</span><br><span class="line">        <span class="comment">// 将.js文件交给id为babel的happypack实例来执行</span></span><br><span class="line">        <span class="comment">// 1) 用happypack/loader代原始的loaders列表</span></span><br><span class="line">        use: <span class="string">&#x27;happypack/loader?id=babel&#x27;</span>,</span><br><span class="line">        <span class="comment">// 排除 node_modules 目录下的文件，node_modules 目录下的文件都是采用的 ES5 语法，没必要再通过 Babel 去转换</span></span><br><span class="line">        <span class="attr">exclude</span>: path.resolve(__dirname, <span class="string">&#x27;node_modules&#x27;</span>),</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">plugins</span>: [</span><br><span class="line">    <span class="comment">// 2)创建一个plugin</span></span><br><span class="line">    <span class="keyword">new</span> HappyPack(&#123;</span><br><span class="line">      <span class="comment">// id标识happypack处理那一类文件</span></span><br><span class="line">      <span class="attr">id</span>: <span class="string">&#x27;babel&#x27;</span>,</span><br><span class="line">      <span class="comment">// 共享线程池</span></span><br><span class="line">      <span class="attr">threadPool</span>: happyThreadPool,</span><br><span class="line">      <span class="comment">// 3) 配置一个替代步骤1) 中的loader</span></span><br><span class="line">      <span class="attr">loaders</span>: [ <span class="string">&#x27;babel-loader&#x27;</span> ],</span><br><span class="line">      <span class="comment">// 日志输出</span></span><br><span class="line">      <span class="attr">verbose</span>: <span class="literal">true</span></span><br><span class="line">    &#125;)</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>在module中定义loader rules告诉 webpack 如何处理特定格式的文件，调用基础配置里的happy/loader，此loader会通过参数的id遍历真实的插件数组，然后找到对应的happyPlugin，通过happyPlugin的配置获取真实的Loader并通过之前初始化完成的多线程进行编译，将编译结果传递给主线程。编译完成后，插件还会针对编译的结果缓存，以及新编译的文件进行缓存的设置。<br>​</p>
<p>在实例化 HappyPack 插件的时候，HappyPack 支持如下参数：</p>
<ol>
<li><code>loaders:Array</code>：</li>
</ol>
<p>由一个转换文件的loader名和一个查询字符串组成。例如：<code>use: &#39;happypack/loader?id=babel&#39;</code>，用happypack/loader代原始的loaders列表，唯一的happyPack plugin标识，用于在modules rules中去识别对应的happyPack实例中的loaders去执行文件的转换操作。<br>​</p>
<ol start="2">
<li><code>id: String</code></li>
</ol>
<p>happy plugin 的唯一标识。默认值”1”，如果只有一个happy plugin可以不指定，当使用不止一个happy plugin时需要指定它。<br>​</p>
<ol start="3">
<li><code>threads: Number</code></li>
</ol>
<p>代表开启几个子进程去处理这一类型的文件，默认是3个，类型必须是整数。<br>​</p>
<ol start="4">
<li><code>threadPool: HappyThreadPool</code></li>
</ol>
<p>代表共享进程池，即多个 HappyPack 实例都使用同一个共享进程池中的子进程去处理任务，以防止资源占用过多。默认值：null。<br>​</p>
<ol start="5">
<li><code>verbose: Boolean</code></li>
</ol>
<p>是否允许 HappyPack 输出日志，默认是 true。<br>​</p>
<blockquote>
<p>HappyPack 并不是完全支持所有的webpack loader API，具体支持情况请查看<a target="_blank" rel="noopener" href="https://github.com/amireh/happypack/wiki/Webpack-Loader-API-Support">官方wiki</a> 。</p>
</blockquote>
<h2 id="HappyPack原理"><a href="#HappyPack原理" class="headerlink" title="HappyPack原理"></a>HappyPack原理</h2><p><img src="/2021/11/26/webpack-happyPack/1.png" alt="img"></p>
<p>HappyPack是webpack和主要来源文件（如JS源代码）之间的中间件，其中发生了大量的文件转换处理。每次webpack解析一个模块时，HappyPack都会获取它（模块）及其所有依赖项，并将这些文件分发给多个工作线程”线程”。<br>这些线程实际上是调用转换器的简单node进程。当加载到编译后的版本时，HappyPack会将最终的chunk提供给加载程序。</p>
<h2 id="不同webpack版本下使用建议"><a href="#不同webpack版本下使用建议" class="headerlink" title="不同webpack版本下使用建议"></a>不同webpack版本下使用建议</h2><blockquote>
<p><img src="/2021/11/26/webpack-happyPack/2.png" alt="img"></p>
</blockquote>
<p>问：对webpack2&amp;3有效吗？<br>答：有，webpack2&amp;3需要搭配使用happyPack@^4.0.1<br>问：对于webpack4有效吗？<br>答：webpack4可能不太需要。<br>大意：webpack4已经融合了多线程机制（HappyPack做的工作），因此happypack的作用不是很明显。如果你使用的版本是&lt;4，那么还是可以继续使用HappyPack。在webpack4中有个<a target="_blank" rel="noopener" href="https://github.com/webpack-contrib/thread-loader">thread-loader</a>，配置起来更简单，两种方式都可以试一下看看那种方案对你来说最优。</p>
<h2 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h2><ul>
<li><a target="_blank" rel="noopener" href="https://www.npmjs.com/package/happypack">https://www.npmjs.com/package/happypack</a></li>
<li><a target="_blank" rel="noopener" href="http://webpack.wuhaolin.cn/4%E4%BC%98%E5%8C%96/4-3%E4%BD%BF%E7%94%A8HappyPack.html">http://webpack.wuhaolin.cn</a></li>
</ul>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.6.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.6.0/dist/mindmap.min.css"> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/webpack/" rel="tag">webpack</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-interview-question-htmlcss"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/17/interview-question-htmlcss/"
    >HTML、CSS面试题</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/17/interview-question-htmlcss/" class="article-date">
  <time datetime="2021-10-17T17:42:45.000Z" itemprop="datePublished">2021-10-17</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h5 id="1-盒模型的两种标准？如何相互转化"><a href="#1-盒模型的两种标准？如何相互转化" class="headerlink" title="1. 盒模型的两种标准？如何相互转化"></a>1. 盒模型的两种标准？如何相互转化</h5><h5 id="2-BFC"><a href="#2-BFC" class="headerlink" title="2. BFC"></a>2. BFC</h5><h5 id="3-伪类的伪元素用法与区别"><a href="#3-伪类的伪元素用法与区别" class="headerlink" title="3. 伪类的伪元素用法与区别"></a>3. 伪类的伪元素用法与区别</h5><h5 id="4-div宽度为100vw-设置宽高固定比为10-1-怎么设置"><a href="#4-div宽度为100vw-设置宽高固定比为10-1-怎么设置" class="headerlink" title="4. div宽度为100vw,设置宽高固定比为10:1,怎么设置"></a>4. div宽度为100vw,设置宽高固定比为10:1,怎么设置</h5><h5 id="5-Flex-1完整写法，分别代表什么意思"><a href="#5-Flex-1完整写法，分别代表什么意思" class="headerlink" title="5. Flex:1完整写法，分别代表什么意思"></a>5. Flex:1完整写法，分别代表什么意思</h5><h5 id="6-flex的实现原理"><a href="#6-flex的实现原理" class="headerlink" title="6. flex的实现原理"></a>6. flex的实现原理</h5><h5 id="7-flex垂直居中兼容ie"><a href="#7-flex垂直居中兼容ie" class="headerlink" title="7. flex垂直居中兼容ie"></a>7. flex垂直居中兼容ie</h5><h5 id="8-rem的使用原理"><a href="#8-rem的使用原理" class="headerlink" title="8. rem的使用原理"></a>8. rem的使用原理</h5><h5 id="9-移动端300毫秒延迟，怎么解决的"><a href="#9-移动端300毫秒延迟，怎么解决的" class="headerlink" title="9. 移动端300毫秒延迟，怎么解决的"></a>9. 移动端300毫秒延迟，怎么解决的</h5><h5 id="10-回流和重汇"><a href="#10-回流和重汇" class="headerlink" title="10. 回流和重汇"></a>10. 回流和重汇</h5> 
      <a class="article-more-link" href="/2021/10/17/interview-question-htmlcss/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/HTML%E3%80%81CSS/" rel="tag">HTML、CSS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%9D%A2%E8%AF%95%E9%A2%98/" rel="tag">面试题</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-interview-question-js"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/17/interview-question-js/"
    >JS系列面试题</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/17/interview-question-js/" class="article-date">
  <time datetime="2021-10-17T14:12:00.000Z" itemprop="datePublished">2021-10-17</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h5 id="1-数据类型有哪些"><a href="#1-数据类型有哪些" class="headerlink" title="1. 数据类型有哪些"></a>1. 数据类型有哪些</h5><h5 id="2-For-of-和-for-in-的区别"><a href="#2-For-of-和-for-in-的区别" class="headerlink" title="2. For of 和 for in 的区别"></a>2. For of 和 for in 的区别</h5><h5 id="3-Map和-object-的区别有哪些，weakMap了解么，和Map区别是什么"><a href="#3-Map和-object-的区别有哪些，weakMap了解么，和Map区别是什么" class="headerlink" title="3. Map和 object 的区别有哪些，weakMap了解么，和Map区别是什么"></a>3. Map和 object 的区别有哪些，weakMap了解么，和Map区别是什么</h5><h5 id="4-为什么要进行垃圾回收，垃圾回收的原理"><a href="#4-为什么要进行垃圾回收，垃圾回收的原理" class="headerlink" title="4. 为什么要进行垃圾回收，垃圾回收的原理"></a>4. 为什么要进行垃圾回收，垃圾回收的原理</h5><h5 id="5-0-1-0-2等于0-3么，为什么不等，有什么好的处理办法么，10转成二进制怎么表示"><a href="#5-0-1-0-2等于0-3么，为什么不等，有什么好的处理办法么，10转成二进制怎么表示" class="headerlink" title="5. 0.1+0.2等于0.3么，为什么不等，有什么好的处理办法么，10转成二进制怎么表示"></a>5. 0.1+0.2等于0.3么，为什么不等，有什么好的处理办法么，10转成二进制怎么表示</h5><h5 id="6-继承有哪些方式，最有效是哪种，如何实现的"><a href="#6-继承有哪些方式，最有效是哪种，如何实现的" class="headerlink" title="6. 继承有哪些方式，最有效是哪种，如何实现的"></a>6. 继承有哪些方式，最有效是哪种，如何实现的</h5><h5 id="7-Var和let的区别有哪些-浏览器环境下-全局作用域的let和var-声明变量会挂载到-window上么-const的值可以修改么，为什么"><a href="#7-Var和let的区别有哪些-浏览器环境下-全局作用域的let和var-声明变量会挂载到-window上么-const的值可以修改么，为什么" class="headerlink" title="7. Var和let的区别有哪些, 浏览器环境下,全局作用域的let和var 声明变量会挂载到 window上么 ,const的值可以修改么，为什么"></a>7. Var和let的区别有哪些, 浏览器环境下,全局作用域的let和var 声明变量会挂载到 window上么 ,const的值可以修改么，为什么</h5><h5 id="8-Object-defineProperty的作用是什么，和proxy的区别"><a href="#8-Object-defineProperty的作用是什么，和proxy的区别" class="headerlink" title="8. Object.defineProperty的作用是什么，和proxy的区别"></a>8. Object.defineProperty的作用是什么，和proxy的区别</h5><h5 id="9-reduce用法"><a href="#9-reduce用法" class="headerlink" title="9. reduce用法"></a>9. reduce用法</h5><h5 id="10-防抖和节流使用场景"><a href="#10-防抖和节流使用场景" class="headerlink" title="10. 防抖和节流使用场景"></a>10. 防抖和节流使用场景</h5> 
      <a class="article-more-link" href="/2021/10/17/interview-question-js/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JS/" rel="tag">JS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%9D%A2%E8%AF%95%E9%A2%98/" rel="tag">面试题</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-interview-question-vue"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/17/interview-question-vue/"
    >VUE系列面试题</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/17/interview-question-vue/" class="article-date">
  <time datetime="2021-10-17T13:51:18.000Z" itemprop="datePublished">2021-10-17</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h5 id="1-vue双向绑定的原理"><a href="#1-vue双向绑定的原理" class="headerlink" title="1. vue双向绑定的原理"></a>1. vue双向绑定的原理</h5><h5 id="2-vue通信方式"><a href="#2-vue通信方式" class="headerlink" title="2. vue通信方式"></a>2. vue通信方式</h5><h5 id="3-组件中的data用箭头函数行不行"><a href="#3-组件中的data用箭头函数行不行" class="headerlink" title="3. 组件中的data用箭头函数行不行"></a>3. 组件中的data用箭头函数行不行</h5><h5 id="4-vue生命周期"><a href="#4-vue生命周期" class="headerlink" title="4. vue生命周期"></a>4. vue生命周期</h5><h5 id="5-vue的keep-alive"><a href="#5-vue的keep-alive" class="headerlink" title="5. vue的keep-alive"></a>5. vue的keep-alive</h5><h5 id="6-vue与react有什么相同点-不同点"><a href="#6-vue与react有什么相同点-不同点" class="headerlink" title="6. vue与react有什么相同点/不同点"></a>6. vue与react有什么相同点/不同点</h5><h5 id="7-vue的-listeners"><a href="#7-vue的-listeners" class="headerlink" title="7. vue的 $listeners"></a>7. vue的 $listeners</h5><h5 id="8-vue修饰符-sync"><a href="#8-vue修饰符-sync" class="headerlink" title="8. vue修饰符.sync"></a>8. vue修饰符.sync</h5><h5 id="9-vue的渲染是异步还是同步，为什么"><a href="#9-vue的渲染是异步还是同步，为什么" class="headerlink" title="9. vue的渲染是异步还是同步，为什么"></a>9. vue的渲染是异步还是同步，为什么</h5><h5 id="10-vue的nextTick的用法及场景"><a href="#10-vue的nextTick的用法及场景" class="headerlink" title="10. vue的nextTick的用法及场景"></a>10. vue的nextTick的用法及场景</h5> 
      <a class="article-more-link" href="/2021/10/17/interview-question-vue/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/VUE/" rel="tag">VUE</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%9D%A2%E8%AF%95%E9%A2%98/" rel="tag">面试题</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-hexo-upgrade"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/09/26/hexo-upgrade/"
    >Hexo更换主题出现空白index.html</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/09/26/hexo-upgrade/" class="article-date">
  <time datetime="2021-09-26T15:32:00.000Z" itemprop="datePublished">2021-09-26</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>搭建博客很久了，之前用的<code>yilia</code>主题很喜欢，最近又”移情别恋”上了 <code>ayer</code> 这种简单有点技术控的风格主题，又开始折腾一番。下面记录一下我的折腾轨迹…</p>
<p>版本：<br><code>hexo: 4.2.1</code><br><code>hexo-cli: 3.1.0</code><br><code>node: 12.13.0</code></p>
<h2 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h2><p>更换主题</p> 
      <a class="article-more-link" href="/2021/09/26/hexo-upgrade/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Hexo/" rel="tag">Hexo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Hexo%E7%89%88%E6%9C%AC%E5%8D%87%E7%BA%A7/" rel="tag">Hexo版本升级</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="vue-vue-elementui-diary"
  class="article article-type-vue"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/09/24/vue-elementui-diary/"
    >vue-elementui-diary</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/09/24/vue-elementui-diary/" class="article-date">
  <time datetime="2021-09-24T09:44:30.000Z" itemprop="datePublished">2021-09-24</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/VUE/">VUE</a> / <a class="article-category-link" href="/categories/VUE/VUE2/">VUE2</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h5 id="title"><a href="#title" class="headerlink" title="title"></a>title</h5><!-- <blockquote class="pullquote mindmap mindmap-md"><ul>
<li><p><a target="_blank" rel="noopener" href="https://hunterx.xyz/hexo-simple-mindmap-plugin-intro.html">Hexo 的思维导图插件</a></p>
<ul>
<li>前言</li>
<li>使用方法<ul>
<li>一</li>
<li>二</li>
<li>三</li>
</ul>
</li>
<li>太长不看</li>
<li>参考资料</li>
</ul>
</li>
</ul>
</blockquote> -->

<div style="width: 90%;margin: 0 auto">
    <canvas id="chart2088" style="height: 300px"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
<script type="text/javascript">
    var ctx = document.getElementById('chart2088').getContext('2d');
    var options = {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45]
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Chart.js Line Chart'
}
}
};
    new Chart(ctx, options);
</script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.6.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.6.0/dist/mindmap.min.css"> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/VUE/" rel="tag">VUE</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/VUE2/" rel="tag">VUE2</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-file-down"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/09/23/file-down/"
    >文件下载的三种方式</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/09/23/file-down/" class="article-date">
  <time datetime="2021-09-23T14:29:09.000Z" itemprop="datePublished">2021-09-23</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E6%96%87%E4%BB%B6/">文件</a> / <a class="article-category-link" href="/categories/%E6%96%87%E4%BB%B6/%E4%B8%8B%E8%BD%BD/">下载</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>文件上传下载是项目中经常遇到的常规功能，本文针对下载功能总结了一共三种使用方式。</p>
<h5 id="一-无-API-浏览器直接下载（静态资源在前端）"><a href="#一-无-API-浏览器直接下载（静态资源在前端）" class="headerlink" title="一.无 API 浏览器直接下载（静态资源在前端）"></a>一.无 API 浏览器直接下载（静态资源在前端）</h5><p>将静态资源文件直接放于<code> public</code> 目录下，打包时 <code>public</code> 文件不会被编译。</p>
<blockquote>
<p>注意：静态资源的路径，在 public 文件夹下路径是<code>/文件名</code></p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">&quot;download-file&quot;</span> <span class="attr">href</span>=<span class="string">&quot;/file.xlsx&quot;</span> <span class="attr">download</span>=<span class="string">&quot;模板.xlsx&quot;</span>&gt;</span>下载模板文件<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>或者使用非 a 标签的按钮下载：</p> 
      <a class="article-more-link" href="/2021/09/23/file-down/"
        >阅读更多...</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E4%B8%8A%E4%BC%A0-%E4%B8%8B%E8%BD%BD/" rel="tag">上传/下载</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
  </article>
  

  
  <nav class="page-nav">
    
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><a class="extend next" rel="next" href="/page/2/">下一页</a>
  </nav>
  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2021
        <i class="ri-heart-fill heart_icon"></i> Lillian
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/assets/imgs/header.png" alt="默"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/travel">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/photos">摄影</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/10/01/about/">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/assets/imgs/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/assets/imgs/weixin.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"log":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":160,"height":300},"mobile":{"show":false,"scale":0.5}});</script></body>

</html>